package cn.edu.tjufe.llp.tin.model.bsc;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ForeignKey;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import cn.edu.tjufe.llp.tin.model.BaseEntity;
import lombok.Getter;
import lombok.Setter;


@Getter
@Setter
//@Builder
//@NoArgsConstructor
//@AllArgsConstructor
@Entity
@Table(name = "bsc_chapter", 
		indexes = {
				@Index(columnList = "name, deleted", name = "ux_bsc_chapter_name", unique = true) }, 
		uniqueConstraints = {
				@UniqueConstraint(columnNames = { "name", "deleted" }, name = "uc_bsc_chapter_name") })
public class BscChapter extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 7713204751677079211L;

	@Column(nullable = false, length = 32)
	private String name;

	@Column(nullable = false, length = 200)
	private String summary;

	@Column(nullable = false, length = 5000)
	private String content;

	@ManyToOne(fetch = FetchType.LAZY, optional = false)
	// @JoinColumn(foreignKey = @ForeignKey(value = ConstraintMode.NO_CONSTRAINT))  // 不生成外键，NO_CONSTRAINT
	// @JoinColumn(name = "book", nullable = false, foreignKey = @ForeignKey(name = "FK_chapter_book"))		// 指定外键的名字
	@JoinColumn(nullable = false, foreignKey = @ForeignKey(name = "FK_chapter_book"))		// 指定外键的名字
	private BscBook book;

}
